import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;




public class AdministradorPersistencia 
{
	private Connection con;
	
	public void releaseConnection()
	{
		try
		{
			con.close();
		}
		catch(Exception e){}
	}
	public void connect()
	{
		try
		{
            String userName = "Prueba";
            String password = "san";
            String url = "jdbc:sqlserver://localhost:1433";
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            con = DriverManager.getConnection (url, userName, password);
        }
        catch (Exception e)
        {
            System.err.println ("Cannot connect to database server");
        }
		
	}
	public ResultSet ejecutarSelect()
	{
		try
		{
			Statement s = con.createStatement ();
			String sentencia = "SELECT * FROM examen01.dbo.alumnos";
			s.executeQuery (sentencia);
			ResultSet rs = s.getResultSet ();
		    return rs;
		   			   
		}
		catch (Exception e)
		{
			System.out.println("Error Query: " + e.getMessage());
			return null;
		}
	}
	public void ejecutarUpdate(String dni, String nombre)
	{
		try
		{
			Statement s = con.createStatement ();
			String sentencia = "UPDATE examen01.dbo.alumnos set nombre = '" + nombre +"' where lu = '"+dni+"'";
			s.executeUpdate(sentencia);
			
		   			   
		}
		catch (Exception e)
		{
			System.out.println("Error Query: " + e.getMessage());
			
		}
	}
	public void ejecutarInsert(String dni, String nombre, String dom)
	{
		try
		{
			Statement s = con.createStatement ();
			String sentencia = "INSERT INTO examen01.dbo.alumnos VALUES (nombre,dni,dom)";
			s.executeUpdate(sentencia);			
		}
		catch (Exception e)
		{
			System.out.println("Error Query: " + e.getMessage());
			
		}
		
		
	}
	
	public void ejecutarDelete(String dni)
	{
		
	}
}
